package com.lyEducation.services.video;

import com.lyEducation.core.video.VideoQueryEnum;
import com.lyEducation.core.video.VideoService;
import com.lyEducation.entities.video.VideoEntity;
import com.lyEducation.repository.VideoRepository;
import com.lyEducation.services.base.BaseDateServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;

@Service
public class VideoServiceImpl extends BaseDateServiceImpl<VideoEntity> implements VideoService {
    @Autowired
    private VideoRepository videoRepository;

    @Override
    public Collection<VideoEntity> findData(Object o) {
        VideoQueryEnum videoQueryEnum = (VideoQueryEnum) o;
        String sql = null;
        if (VideoQueryEnum.MOSTCOMMENT.equals(videoQueryEnum)) {
            sql = "SELECT * FROM VideoEntity as v ORDER BY v.createTime DESC LIMIT 5";
            return videoRepository.list(sql);
        } else if (VideoQueryEnum.NEW.equals(videoQueryEnum)) {
            sql = "SELECT * FROM video as v ORDER BY v.createTime DESC LIMIT 5";
            return videoRepository.findByNativeQuery(sql, null);
        }
        return null;
    }


}
